<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<%@ page import="com.conversationboard.model.*" %>
<%@ page import="com.conversationboard.view.*" %>
<%@ page import="com.conversationboard.config.*" %>
<%@ page import="java.net.URLEncoder" %>

<%@page pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>

<% 
	String terms = (String) request.getAttribute("terms");
	int offset = (Integer) request.getAttribute("offset");
	String searchType = (String) request.getAttribute("searchtype");
	String startDate = (String) request.getAttribute("startdate");
	String endDate = (String) request.getAttribute("enddate");
	String artefact = (String) request.getAttribute("artefact");
	String idType = (String) request.getAttribute("idtype");
	String sortOrder = (String) request.getAttribute("sortorder");
	int boardId = (Integer) request.getAttribute("boardid");
	
	terms = URLEncoder.encode(terms, "UTF-8");
	
	String postbackParameters = "?terms=" + terms + "&amp;offset=" + offset + "&amp;searchtype=" + searchType + "&amp;startdate=" + startDate + "&amp;enddate=" + endDate + "&amp;artefact=" + artefact + "&amp;idtype=" + idType + "&amp;sortorder=" + sortOrder + "&amp;boardid=" + boardId;
	
	User user = User.get(request.getUserPrincipal());
	request.setAttribute("user", user);

%>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>Search Results</title>
		<link rel="stylesheet" type="text/css" href="<%=Configuration.getInstance().getRoot()%>/Stylesheets/<%=StyleSheets.getStyleSheetFileName(request.getCookies())%>">
	</head>

	<body>
	
		<%= MainMenu.display(request.getUserPrincipal(), Page.SEARCH) %>

		<div class="headingblock">
			<h1>Search Results</h1>
		</div>
		
		<div class="mainblock">

			<div class="formsection">
				<c:forEach var="hit" items="${requestScope.hits}">

					<c:choose>
						<c:when test="${not hit.deleted}">
							<p><a href="<%=Configuration.getInstance().getRoot()%>/ThreadSelectedControllerServlet?showall=true&boardid=${hit.boardId}&threadid=${hit.threadId}&bookmarkedmessageid=${hit.messageId}"><strong>${hit.displayName}</strong> wrote this on thread <span class="green"><strong>${hit.threadTitle}</strong></span> on board <strong>${hit.boardName}</strong> on <fmt:formatDate type="date" dateStyle="medium" timeStyle="short" value="${hit.timestampAsDate}"></fmt:formatDate></a><span class="boarddescription"></span></p>
							<div class="searchresult">${hit.text}</div>
						</c:when>
					
						<c:otherwise>
							<c:if test="${user.siteAdmin}">
								<p><a href="<%=Configuration.getInstance().getRoot()%>/ThreadSelectedControllerServlet?showall=true&boardid=${hit.boardId}&threadid=${hit.threadId}&bookmarkedmessageid=${hit.messageId}"><strong>${hit.displayName}</strong> wrote this on thread <span class="green"><strong>${hit.threadTitle}</strong></span> on board <strong>${hit.boardName}</strong> on <fmt:formatDate type="date" dateStyle="medium" timeStyle="short" value="${hit.timestampAsDate}"></fmt:formatDate></a><span class="boarddescription"></span></p>
								<div class="searchresult"><strong>Message Has Been Deleted (<a href="${contextPath}/Pages/Admin/confirm.jsp?action=undeletemessage&boardid=${hit.boardId}&threadid=${hit.threadId}&messageid=${hit.messageId}">Undelete Message</a>)</strong>${hit.text}</div>
							</c:if>
						</c:otherwise>
					</c:choose>					

				</c:forEach>
				
				<br /><br />
				
				<a href="<%=Configuration.getInstance().getRoot()%>/Pages/Search/search.jsp">Search Again...</a>
				
				<c:if test="${nextavailable}">
					<a href="<%=Configuration.getInstance().getRoot()%>/FullTextSearchControllerServlet<%=postbackParameters%>">Next...</a>
				</c:if>
				
			</div>
		</div>
	
		<!--<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>-->
		<!--<script type="text/javascript">_uacct = "UA-1148679-1";urchinTracker();</script>--> 
	
	</body>
	
</html>
